import java.util.*;

public class Main {

    static int maxn = 1002;
    static int n;
    static int[][] a = new int[maxn][maxn];
    static int[][] record = new int[maxn][maxn];

    public static int sum(int i, int j) {
        if (record[i][j] != -1) {
            return record[i][j];
        }
        if (i > n) {
            return 0; // Add this line to handle the out-of-bounds case
        }
        if (i == n) {
            record[i][j] = a[i][j];
            return a[i][j];
        } else if (i < n) {
            record[i][j] = a[i][j] + Math.max(sum(i + 1, j), sum(i + 1, j + 1));
            return record[i][j];
        }
        return 0;
    }

    public static void main(String [] args) {
        for (int i = 1; i < 1002; i++) {
            for (int j = 1; j < 1002; j++) {
                record[i][j] = -1;
            }
        }
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= i; j++) {
                a[i][j] = sc.nextInt();
            }
        }
        System.out.println(sum(1, 1));
        sc.close();
    }

}
